// 使用myAjax需要先引入jquery

// const API_URL = 'http://ecourse.xqb.ink'
// const API_URL = 'http://localhost:3000'
const API_URL = 'http://82.157.129.105'

let token = localStorage.getItem('token')

function myAjax( {url,data={},method='get'} ) {

    /*
      {url,data={},method='get'} =  {
            url:'http://localhost:3000/api/courseinfo',
            data:{
                type:1
            }
        }
    */

    if( !url ){
        alert('请传递合法的url地址')
        return
    }
    // return
    return new Promise((resolve, reject) => {
        $.ajax({
            url:API_URL + url,
            data,
            method,
            headers:{
                authorization:token
            },
            success(result) {
                resolve( { result } )
            },
            error(err) {
                resolve( { err } )
            }
        })
    })
}